package str;
 
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
 
public class ClientForSave { 
 
    @SuppressWarnings("deprecation")
	public static void main(String[] args)
    {
 
        @SuppressWarnings("deprecation")
		AnnotationConfiguration cfg=new AnnotationConfiguration();
        cfg.configure("hibernate.cfg.xml");
 
        SessionFactory factory = cfg.buildSessionFactory();
        Session session = factory.openSession();
        Product p=new Product(); 
 
        p.setProductId(108);
        p.setProName("javaken");
        p.setPrice(12000);
 
        Transaction tx = session.beginTransaction();
        session.save(p);
        System.out.println("Object saved successfully using annotations.....!!");
       
        Query q= session.createQuery("FROM Product AS E");
        System.out.println("Object is queried:");
        List<Product> l=q.list();
       for(Product p1:l){
    	   System.out.println(p1);
       }
        //Object o=session.get(Product.class, 106);
        //System.out.println(o);
        tx.commit();
        session.close();
        factory.close();
    }
 
}